package com.efast.dmom.mgmt.service.mes.report.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.dmom.mgmt.bean.mes.report.EachQualityGateDoorIndexBean;
import com.efast.dmom.mgmt.dao.mes.report.EachQualityGateDoorDataDao;
import com.efast.dmom.mgmt.service.mes.report.EachQualityGateDoorDataService;

@Service
public class EachQualityGateDoorDataServiceImpl implements EachQualityGateDoorDataService{
	
	@Autowired
	private EachQualityGateDoorDataDao eachQualityGateDoorDataDao;
	

	@Override
	public void insertEachQualityGateDoorData(String isNow) {
		eachQualityGateDoorDataDao.deleteAll(isNow);
		List<EachQualityGateDoorIndexBean> eachQualityGateDoorData = eachQualityGateDoorDataDao.selectQtyAndDefectQty(isNow);
		if (eachQualityGateDoorData != null && eachQualityGateDoorData.size() > 0) {
			for (EachQualityGateDoorIndexBean data:eachQualityGateDoorData) {
				double DPV = deciMal(data.getDayDefectQty(),data.getDayQty());
				double FTQ = deciMal((data.getDayQty() - data.getDefectDayQty()),data.getDayQty());
				data.setDayDPVData(DPV);
				data.setDayFTQData(FTQ);
			}
	    eachQualityGateDoorDataDao.insertData(eachQualityGateDoorData);	
		}		
	}
	
	public double deciMal(int top, int below) {
        double result = new BigDecimal((float)top / below).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return result;
    }
	
}
